<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简化对象写法</title>
</head>
<body>
    <script>
        //ES6允许再大括号里面进行直接写入变量和函数,作为对象的属性和方法.
        //书写的更加简洁

        let name = '简化对象';

        let improve = function(){ 
            console.log('let 可以简化对象的书写方式');
        }

        //做教案 
        let MakeLessonPlans = function(){
            console.log('老师正在做教案');
        } 

        //属性和方法的简写 
        // let 直接加对象和属性是错误的
        /**
         * 
         * let teacher = {
            name,
            age,
            salary,
            teach() {
                console.log('老师进行上课');
            }
        };
        错误:简化对象写法.html:24 Uncaught ReferenceError: salary is not defined
        **/

        // const 常量 ,其属性必须要进行设置值,否组报错
        const teacher = {
            name,//name的值前面我们已经设置过了,所以不会报错
            age : 80,
            salary : 5000,
            teach() {
                console.log('老师进行上课');
            }
        };
        console.log(teacher);
        let op ;
        let teacher2 = {
            
            skills,
            // let创建的属性 也不可以 值为空
            // Uncaught ReferenceError: skills is not defined
            // at 简化对象写法.html:53:13
            MakeLessonPlans,
            // 承载上个方法
            teach() {
                console.log('老师进行上课');
            }
        };
        console.log(teacher);

        
    </script>
    
</body>
</html>